nums=[1,2,3]
def permute(nums):
    size=len(nums)
    if len(nums)==0:
        return []
    used=[False for _ in range(size)]
    res=[]
    backtracking(nums,size,0,[],used,res)
    return res
def backtracking(nums,size,depth,path,used,res):
    if depth==size:
        res.append(path[:])
        return None
    for i in range(size):
        if not used[i]:
            used[i]=True
            path.append(nums[i])
            backtracking(nums,size,depth+1,path,used,res)
            #进行回溯，状态标记恢复
            used[i]=False
            path.pop()
print(permute(nums))